package com.example.demo.config;

import jakarta.servlet.http.HttpSession;
import jakarta.websocket.HandshakeResponse;
import jakarta.websocket.server.HandshakeRequest;
import jakarta.websocket.server.ServerEndpointConfig;

public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        //获取httpsession对象，websocket中取不到httpsession对象，通过这里获取
        HttpSession httpSession = (HttpSession) request.getHttpSession();
        //将该对象保存起来
        //sec.getUserProperties().put(HttpSession.class.getName(),httpSession);
//        System.out.println(httpSession.getId());
    }
}
